﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.Result
{
    public abstract class ErrorCaseBase<TEnum>
        where TEnum : Enum
    {
        public TEnum? ErrorCode { get; private set; }
        public string[] ErrorInterpolate { get; protected set; }

        internal ErrorCaseBase()
        {
            this.ErrorInterpolate = Array.Empty<string>();
        }

        public ErrorCaseBase(TEnum code, string[] interpolate)
        {
            this.ErrorCode = code;
            this.ErrorInterpolate = interpolate;
        }

        public ErrorCaseBase(TEnum code) : this()
        {
            this.ErrorCode = code;
        }

        internal abstract string Translate(TEnum code);

        public override string ToString()
        {
            if (this.ErrorCode == null)
                return base.ToString() ?? string.Empty;
            else
                return string.Format(this.Translate(this.ErrorCode), this.ErrorInterpolate);
        }
    }
}
